package com.coscon.controller;

import cn.hutool.system.SystemUtil;
import com.coscon.config.ApplicationStartup;
import com.coscon.controller.base.BaseController;
import com.coscon.service.ConfigService;
import com.coscon.service.OshiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 用户相关controller
 *
 * @author 409390047@qq.com
 * @date 2018/7/9
 * @since 1.0.0
 */
@Controller
@RequestMapping("/jm/manager/home")
@Slf4j
public class UserHomeController extends BaseController {

    @Resource
    private ApplicationStartup applicationStartup;
    @Resource
    private ConfigService configService;
    @Resource
    private OshiService oshiService;
    /**
     * 用户首页
     * @author 409390047@qq.com
     * @date 2021/6/9 17:10
     * @since 1.0.0
     * @return java.lang.String
     */
    @GetMapping("/index")
    public ModelAndView userIndex(HttpServletRequest request){
        ModelAndView v = new ModelAndView("index");
        //webscoket url
        v.addObject("wsUrl" , super.getWebScoketUrl(request));
        String title = "智慧遥控助手/" + SystemUtil.getHostInfo().getAddress();
        v.addObject("title",title);
        //配置中获取，是否开启了安全认证
        String securityIsUser = this.configService.getSysconfigValByKey("security_is_user");
        boolean securityIsUserBoolean = StringUtils.equalsIgnoreCase(securityIsUser,"on");
        v.addObject("security_is_user_boolean",securityIsUserBoolean);

        String userName = this.configService.getSysconfigValByKey("security_system_username");
        if(StringUtils.isBlank(userName)){
            userName = SystemUtils.USER_NAME;
        }
        v.addObject("userName",userName);

        return v;
    }



    /**
     * 主页
     * @param request
     * @return
     */
    @GetMapping("/welcomePage")
    public ModelAndView welcomePage(HttpServletRequest request){
        ModelAndView v = new ModelAndView("appPage/welcome_iframe");
        v.addObject("checkRobot",applicationStartup.isRebootAuthCheck());


        //内存信息
        v.addAllObjects(this.oshiService.getSystemMemoryInfo());



        return v;
    }





}
